package com.databinding.jetpacktesting.room;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import java.util.List;

/**
 * Created by harisucici on 2020/3/15
 * Class description:
 */
public class WordViewModel extends AndroidViewModel {
    private WordContainer wordContainer;
    private WordDao wordDao;
    private LiveData<List<WordEntity>> allWordsLive;//本身就是子线程同于 flutter

    public WordViewModel(@NonNull Application application) {
        super(application);
        wordContainer = new WordContainer(application);
        //转移到 container
//        WordDataBase wordDataBase = WordDataBase.getInstance(application);
//        wordDao = wordDataBase.getWordDao();
//        allWordsLive = wordDao.getAllWordsLife();
    }

    public LiveData<List<WordEntity>> getAllWordsLive() {
        return wordContainer.getAllWordsLive();
    }

//    public void setAllWordsLive(LiveData<List<WordEntity>> allWordsLive) {
//        this.allWordsLive = allWordsLive;
//    }

    public void insertWords(WordEntity... wordEntities) {
        wordContainer.insertWords(wordEntities);
    }

    public void updateWords(WordEntity... wordEntities) {
        wordContainer.updateWords(wordEntities);
    }

    public void deleteWords(WordEntity... wordEntities) {
        wordContainer.deleteWords(wordEntities);
    }

    public void deleteAll() {
        wordContainer.deleteAll();
    }


}
